package ru.sh.ui;

import ru.sh.screen.SHGameScreen;
import android.view.MotionEvent;
import framework.GameCamera;
import framework.GameResources;
import framework.GameScreen;
import framework.managers.SystemInfoManager;
import framework.managers.TextureManager;
import framework.objects.hero.Hero;
import framework.objects.ui.UI;
import framework.objects.ui.UIElement;

public class Joy extends UIElement {

	private int r = 70;
	private int r2 = r * r;
	private Hero hero;
	
	public Joy(GameScreen screen, UI ui, float x0, float y0) {
		super(screen, ui, x0, y0);
		hero = ((SHGameScreen)screen).getHero();
		r = height/2;
		r2 = r * r;
	}

	@Override
	public void handle(MotionEvent event) {
		for (int i = 0; i < 2; i++) {
			float dx = event.getX(i) / SystemInfoManager.getScaleX() - x0;
			float dy = (GameCamera.CAMERA_HEIGHT - y0) - event.getY(i) / SystemInfoManager.getScaleY();
			if (dx*dx + dy*dy < r2) {
				hero.setKxKy(dx / r, dy / r);
				return;
			}
		}		
	}

	@Override
	protected void initPresentation() {
		presentation = TextureManager.getTexture(GameResources.getBitmapName(6));
	}

}
